package org.easy.tool.date;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Description: 使用JDK8新日期
 * @Author: wxl
 * @CreateTime: 2022/12/27 15:30
 */
public class DateUtil extends cn.hutool.core.date.DateUtil {

    private static final String PATTERN_YYYY_MM_DD = "yyyyMMdd";

    private static final String PATTERN_YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";

    private static final String PATTERN_YYYY_MM_DD_T_HH_MM_SS_Z = "yyyyMMdd'T'HHmmss'Z'";

    public static String localDateTime () {
        return localDateTime(LocalDateTime.now());
    }

    public static String localDateTime (LocalDateTime localDateTime) {
        return localDateTime (LocalDateTime.now(),PATTERN_YYYY_MM_DD_HH_MM_SS);
    }

    public static String localDateTime (LocalDateTime localDateTime,String pattern) {
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern(pattern);
        return dtf.format(localDateTime);
    }

    public static String conversionTimeFormat(String timeStamp){
        LocalDateTime dateTime = LocalDateTime.parse(timeStamp,DateTimeFormatter.ofPattern(PATTERN_YYYY_MM_DD_T_HH_MM_SS_Z));
        return dateTime.format(DateTimeFormatter.ofPattern(PATTERN_YYYY_MM_DD_HH_MM_SS));
    }

    public static String dateForYmd(){
        return localDateTime (LocalDateTime.now(),PATTERN_YYYY_MM_DD);
    }

    public static void main(String[] args) {
        System.out.println(dateForYmd());
    }

}
